# Clean up temporary migration and verification scripts
Write-Host "=========================================="
Write-Host "Cleaning Up Temporary Script Files"
Write-Host "=========================================="

$rootDir = "D:\kexilo\dexilo-detail\backend"
Set-Location $rootDir

# List of temporary scripts that are no longer needed after migration
$tempScripts = @(
    # Step-by-step migration scripts (step1-step14)
    "step1-create-modules.ps1",
    "step2-migrate-common-to-core.ps1", 
    "step3-verify-common-migration.ps1",
    "step4-migrate-domain-entities.ps1",
    "step5-verify-entities.ps1",
    "step6-migrate-system-services.ps1",
    "step7-verify-services.ps1", 
    "step8-migrate-controllers.ps1",
    "step9-verify-controllers.ps1",
    "step10-migrate-auth.ps1",
    "step11-migrate-audit.ps1",
    "step12-cleanup-admin.ps1",
    "step13-final-verification.ps1",
    "step14-activate-architecture.ps1",
    
    # Migration helper scripts
    "phase3-refactor-to-submodules.ps1",
    "migrate-missing-files.ps1", 
    "migrate-remaining-files.ps1",
    
    # Verification scripts
    "verify-migration-completeness.ps1",
    "verify-migration-safety.ps1",
    "comprehensive-file-placement-check.ps1",
    "find-misplaced-files.ps1",
    
    # Fix and cleanup scripts
    "fix-encoding-issues.ps1",
    "fix-import-paths.ps1", 
    "fix-role-module-migration.ps1",
    "cleanup-old-structure.ps1",
    "cleanup-remaining-files.ps1",
    
    # This cleanup script itself (will be deleted at the end)
    "cleanup-scripts.ps1"
)

# Scripts to keep (useful for ongoing development)
$keepScripts = @(
    "code-quality-check.sh",    # Code quality checking
    "migration-summary.ps1"     # Architecture summary
)

Write-Host "`n📋 Scripts to keep:" -ForegroundColor Green
foreach ($script in $keepScripts) {
    if (Test-Path "scripts\$script") {
        Write-Host "  ✅ $script" -ForegroundColor Green
    }
}

Write-Host "`n🗑️  Scripts to delete:" -ForegroundColor Yellow
$deletedCount = 0
foreach ($script in $tempScripts) {
    $scriptPath = "scripts\$script"
    if (Test-Path $scriptPath) {
        Write-Host "  🗑️  Deleting: $script"
        Remove-Item -Path $scriptPath -Force
        $deletedCount++
    }
}

Write-Host "`n📊 Cleanup Summary:" -ForegroundColor Cyan
Write-Host "  📁 Scripts deleted: $deletedCount"
Write-Host "  📁 Scripts kept: $($keepScripts.Length)"

Write-Host "`n🧹 Final scripts directory:" -ForegroundColor Green
$remainingScripts = Get-ChildItem -Path "scripts\" -Filter "*.ps1" -Name
$remainingShScripts = Get-ChildItem -Path "scripts\" -Filter "*.sh" -Name

Write-Host "📁 scripts/"
foreach ($script in $remainingShScripts) {
    Write-Host "├── 📜 $script (Shell script)" -ForegroundColor Green
}
foreach ($script in $remainingScripts) {
    Write-Host "├── 📜 $script (PowerShell script)" -ForegroundColor Green
}

Write-Host "`n✅ Script cleanup completed!"
Write-Host "Only useful scripts remain for ongoing development."

Write-Host "`n=========================================="
